package com.ucar.training.controller;

import com.ucar.training.domain.User;
import com.ucar.training.service.IUserService;
import com.ucar.training.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author XiongMM
 * @date 2019/7/29 14:49
 * @description
 */
public class UserInfoServlet extends HttpServlet {

    private IUserService userService = new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User user = (User) req.getSession().getAttribute("user");
        req.setAttribute("userName",user.getUserName());
        req.setAttribute("users",userService.selectAll());
        req.getRequestDispatcher("/pages/all_user.jsp").forward(req,resp);
    }
}
